import 'package:foxue/global.dart';
import 'package:foxue/http/api.dart';
import 'package:flutter/material.dart';

class DetailPage extends StatefulWidget {
  DetailPage({Key key, this.id}) : super(key: key);
  final String id;
  @override
  _DetailPageState createState() => _DetailPageState();
}

class _DetailPageState extends State<DetailPage> {
  var _data;
  @override
  void initState() {
    String _id = widget.id;
    getFoxueDetail(_id).then((res) {
      setState(() {
        _data = res;
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return _data == null
        ? Scaffold(
            body: Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              color: Global.backgroundColor,
              child: Center(
                  child: CircularProgressIndicator(
                      backgroundColor: Global.primaryColor)),
            ),
          )
        : Scaffold(
            body: Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              padding: EdgeInsets.fromLTRB(20, 5, 20, 5),
              decoration: BoxDecoration(
                color: Global.backgroundColor,
                image: DecorationImage(
                  image: AssetImage("assets/images/bg.png"),
                  repeat: ImageRepeat.repeat,
                  fit: BoxFit.fill,
                ),
              ),
              child: Stack(
                children: [
                  Positioned(
                    left: 0,
                    right: 0,
                    bottom: 0,
                    child: Container(
                      height: 100,
                      child: Image.asset('assets/images/bottom.png'),
                    ),
                  ),
                  Positioned(
                    top: 0,
                    left: 0,
                    right: 0,
                    bottom: 0,
                    child: SingleChildScrollView(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          SizedBox(height: Global.paddingTop + 5),
                          Row(
                            children: [
                              Container(
                                width: 20,
                                child: Image.asset('assets/images/yun.png'),
                              ),
                              InkWell(
                                onTap: () {
                                  Navigator.of(context).pop();
                                },
                                child: Text(
                                  '返回',
                                  style: TextStyle(
                                    fontWeight: FontWeight.w700,
                                    fontSize: 17,
                                    fontFamily: 'fangzhengkai',
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ],
                          ),
                          Container(
                            width: 130,
                            child: Image.asset('assets/images/icon.png'),
                          ),
                          Text(
                            _data['title'],
                            style: TextStyle(
                              fontWeight: FontWeight.w700,
                              fontSize: 25,
                              fontFamily: 'fangzhengkai',
                              color: Global.fontColor,
                            ),
                          ),
                          SizedBox(height: 15),
                          Text(
                            "　　${_data['content']}",
                            style: TextStyle(
                              fontWeight: FontWeight.w600,
                              fontSize: 19,
                              fontFamily: 'fangzhengkai',
                              color: Global.fontColor,
                              height: 2,
                            ),
                          ),
                          SizedBox(height: 75),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          );
  }
}
